﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Web.Mvc;
using HiLand.Framework.BusinessCore;
using HiLand.General.Entity;
using HiLand.Utility.Cache;
using HiLand.Utility.Data;
using HiLand.Utility.Enums;
using HiLand.Utility4.Data;
using HiLand.Utility4.MVC.Attributes;

namespace Legou365.Web.Areas.Manage.Controllers
{
    [UserAuthorize(UserTypes.SuperAdmin | UserTypes.Manager)]
    public class MainController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult SoftVersion()
        {
            Dictionary<string, string> softVersionDic = new Dictionary<string, string>();

            Assembly assemblyWeb = Assembly.GetExecutingAssembly();
            softVersionDic.Add("运行网站", GetAssemblyInfo(assemblyWeb));

            Assembly assemblyFramework = Assembly.GetAssembly(typeof(BusinessUser));
            softVersionDic.Add("系统框架", GetAssemblyInfo(assemblyFramework));

            Assembly assemblyGeneral = Assembly.GetAssembly(typeof(LoanBasicEntity));
            softVersionDic.Add("组件通用业务", GetAssemblyInfo(assemblyGeneral));

            Assembly assemblyUtility = Assembly.GetAssembly(typeof(AssemblyHelper));
            softVersionDic.Add("组件Utility2", GetAssemblyInfo(assemblyUtility));

            Assembly assemblyUtility4 = Assembly.GetAssembly(typeof(StringEx));
            softVersionDic.Add("组件Utility4", GetAssemblyInfo(assemblyUtility4));

            return View(softVersionDic);
        }

        [NonAction]
        private string GetAssemblyInfo(Assembly assembly)
        {
            Version version = assembly.GetName().Version;
            return string.Format("版本号为：{0}.{1}.{2}.{3}<br/>最后编译时间为:{4}", version.Major, version.Minor, version.Build, version.Revision, AssemblyHelper.GetCompiledTime(assembly).ToString("yyyy-MM-dd"));
        }


        public ActionResult CacheInfo()
        {
            ICache cache= CacheFactory.Create();
            return View(cache.Count);
        }

        [HttpPost]
        public ActionResult CacheInfo(bool isOnlyPlaceHolder= true)
        {
            ICache cache = CacheFactory.Create();
            cache.Clear();
            return View(cache.Count);
        }

        public ActionResult Test()
        {
            return View();
        }
    }
}
